package com.itheima.controller;

import com.itheima.common.Com.ShoppingCart;
import com.itheima.common.pojo.Result;
import com.itheima.common.vo.ShoppingCartDto;
import com.itheima.common.vo.ShoppingCartVo;
import com.itheima.service.ShoppingCartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/shoppingCart")
public class ShoppingCartController {

    @Autowired
    private ShoppingCartService shoppingCartService;
    @GetMapping("/list")
    public Result list(){

        List<ShoppingCart> all = shoppingCartService.getAll();

        return Result.success(all);
    }
    @PostMapping("/add")
    public Result save( @RequestBody ShoppingCart shoppingCart){

        ShoppingCartVo save = shoppingCartService.save(shoppingCart);
        return Result.success("成功",save);
    }

    @DeleteMapping("/clean")
    public Result delete(){
        boolean delete = shoppingCartService.delete();
        return Result.success(delete);
    }
    @PostMapping("/sub")
    public Result deleteId(@RequestBody ShoppingCartDto shoppingCartDto){

        boolean b = shoppingCartService.deleteId(shoppingCartDto);
        return Result.success("失败",b);
    }
}
